home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / WAIS / next-ui / IconWell.h < prev    next >
Encoding:
Text File  |  1992-02-03  |  4.9 KB  |  127 lines

  1. // IconWell.h
  2. //
  3. // Free software created 1 Feb 1992
  4. // by Paul Burchard <burchard@math.utah.edu>.
  5. //
  6. // This class creates a well for drag-and-drop of icons.  It conforms to the 
  7. // target-action paradigm of Controls and so may be configured easily in IB.
  8. // In communicating with other objects it works via its stringValue, a 
  9. // TAB-separated list of the complete path names of the file(s) represented by 
  10. // the icon.  Double-clicks open the files; either via the IconWell's delegate,
  11. // if present, or via WorkSpace otherwise.  (Actually, incomplete path names
  12. // work, as long as the icon doesn't depend on the absolute path name, and
  13. // except that you can't double-click to open such an icon.)  The delegate also 
  14. // receives notice when an icon is about to be dragged out in case the file
  15. // needs to be prepared in any way.
  16. //
  17. // To avoid circularity, if an action message is received from the target, our 
  18. // action is not sent back to it.
  19. //
  20. // While IconWells may be dropped into an app in IB like any other Control, two 
  21. // things must be present in the NIB file to support their function: (1) the 
  22. // opaque white 48 x 48 image "Blank.tiff"; (2) one IconWellControl object 
  23. // for each Window in which IconWells appear, created with
  24. //    [[IconWellControl alloc] initWindow:theWindow];
  25. // (you don't have to do anything else with it).
  26. //
  27. // The appearance of the IconWell may be set with the setBezeled: and
  28. // setBordered: methods.  The setHoldOnDrag: method determines whether dragging
  29. // out of the well is a "copy" or "move" operation; i.e., whether or not the
  30. // icon should remain in the well after it has been successfully dragged out.
  31. // Defaults: bezeled, no border, hold on drag.  Dragging and dropping can be
  32. // selectively disabled with the setDraggable:droppable: method.
  33. //
  34. // To implement a different file-opening procedure, create an object with an
  35. //    - (int)openFile:(const char *)fullPath ok:(int *)flag;
  36. // method (see Speaker/Listener class documentation for details), and connect
  37. // it up as the IconWell's delegate in IB.  Similarly, to intercept drag-outs
  38. // and prep files as needed, implement a method like this:
  39. //    - (int)prepFile:(const char *)fullPath ok:(int *)flag;
  40. //
  41. //
  42. // NOTES ON IMPLEMENTATION:
  43. //
  44. // The design of this class is a bit convoluted because drag-and-drop is not 
  45. // implemented in a truly robust or object-oriented way in NeXTstep 2.0.  You 
  46. // have to arrange things just so.
  47. // 
  48. // One problem is that WorkSpace handles drag-and-drop messages window by 
  49. // window; there is no view-level interface yet in NeXTstep.  A Listener which 
  50. // has registered to get all the remote msgs for a window sends them to a 
  51. // single delegate.  It is this delegate, then (an IconWellControl object in 
  52. // this scheme), which must delegate these messages to the individual accepting 
  53. // views.
  54. //
  55. // The scheme used here is enabled just by initializing an IconWellControl for
  56. // each Window; all organizing between IconWells and, IconWellControls, and 
  57. // Listeners is then done automatically.  Presumably, the features of the 
  58. // IconWellControl class could be built into the Window class itself in a 
  59. // future version of NeXTstep.  
  60. //
  61. // Another problem is that WorkSpace is tied up while the drop operation is 
  62. // being completed.  This means that WorkSpace services (such as getting the 
  63. // correct icon for a path) are not available for the IconWell methods that 
  64. // handle drag-and-drop messages.  Thus, low-level PostScript calls are needed 
  65. // for some operations.
  66. //
  67. // TO DO:
  68. //
  69. // Use custom ActionCell subclass so background gray can be set.
  70. //
  71.  
  72. #import <appkit/Control.h>
  73.  
  74. @interface IconWell : Control
  75. {
  76.     id delegate;
  77.     id iconPath;
  78.     char iconName[512];
  79.     BOOL isDropping;
  80.     BOOL isDragging;
  81.     BOOL isDraggable;
  82.     BOOL isDroppable;
  83.     BOOL isHoldOnDrag;
  84.     NXEvent dragFromEvent;
  85. }
  86.  
  87. + initialize;
  88. + wellListFor:aWindow;
  89.  
  90. - initFrame:(const NXRect *)frameRect;
  91. - free;
  92. - windowChanged:newWindow;
  93.  
  94. - setBezeled:(BOOL)flag;
  95. - (BOOL)isBezeled;
  96. - setBordered:(BOOL)flag;
  97. - (BOOL)isBordered;
  98. - setHoldOnDrag:(BOOL)flag;
  99. - (BOOL)isHoldOnDrag;
  100. - setDraggable:(BOOL)dragFlag droppable:(BOOL)dropFlag;
  101. - (BOOL)isDraggable;
  102. - (BOOL)isDroppable;
  103.  
  104. - (const char *)stringValue;
  105. - setStringValue:(const char *)aString;
  106. - takeStringValueFrom:sender;
  107. - clear:sender;
  108.  
  109. - (BOOL)acceptsFirstMouse;
  110. - mouseDown:(NXEvent *)theEvent;
  111. - mouseDragged:(NXEvent *)theEvent;
  112. - mouseUp:(NXEvent *)theEvent;
  113. - (int)iconEntered:(int)windowNum at:(double)x :(double)y
  114.     iconWindow:(int)iconWindowNum iconX:(double)iconX iconY:(double)iconY
  115.     iconWidth:(double)iconWidth iconHeight:(double)iconHeight
  116.     pathList:(char *)pathList;
  117. - (int)iconMovedTo:(double)x :(double)y;
  118. - (int)iconExitedAt:(double)x :(double)y;
  119. - (int)iconReleasedAt:(double)x :(double)y ok:(int *)flag;
  120.  
  121. - (int)openFile:(const char *)fullPath ok:(int *)flag;
  122. - (int)prepFile:(const char *)fullPath ok:(int *)flag;
  123. - setDelegate:anObject;
  124. - delegate;
  125.  
  126. @end
  127.